//
//  CalculatorView.swift
//  Fruta
//
//  Created by yanhangpu on 2021/6/22.
//  Copyright © 2021 Apple. All rights reserved.
//

import SwiftUI

struct CalculatorView: View {
    
    @State private var brain: CalculatorBrain = .left("0")
    
    @ObservedObject var model: CalculatorModel = CalculatorModel()
    
    @State var showAlert = false

    let scale: CGFloat = UIScreen.main.bounds.width / 414
    
    var body: some View {
        VStack(alignment: .center, spacing: 12, content: {
            Spacer()
            CalculatorResultText(title: "0", action: {
                showAlert = true
                
            }).alert(isPresented: $showAlert) { () -> Alert in
                Alert(title: Text("title"), message: Text("message"), primaryButton: .cancel({
                }), secondaryButton: .destructive(Text("Sure"), action: {
                }))
            }
            CalculatorButtonPad(brain: $model.brain)
                .padding(.bottom)
        })
        .background(Image("calculatorBackground"))
        .scaleEffect(scale)
    }
}

struct CalculatorView_Previews: PreviewProvider {
    static var previews: some View {
        CalculatorView()
//        CalculatorView().previewDevice("iPod touch (7th generation)")
    }
}
